package com.deluxelx.soul.inn.service.counselor.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.deluxelx.soul.inn.bean.counselor.Expertise;
import com.deluxelx.soul.inn.common.constant.ChineseCharacter;
import com.deluxelx.soul.inn.mapper.counselor.ExpertiseMapper;
import com.deluxelx.soul.inn.service.counselor.ExpertiseService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 咨询师擅长领域服务类
 *
 * @author: zihao.liao
 * @date: 2024/2/4 17:00
 */
@Service
public class ExpertiseServiceImpl extends ServiceImpl<ExpertiseMapper, Expertise> implements ExpertiseService {

    @Resource
    private ExpertiseMapper expertiseMapper;

    @Override
    public String fetchIndexCounselorExpertise(String counselorId) {
        List<Expertise> expertiseList = expertiseMapper.selectByCounselor(counselorId);
        if (CollectionUtil.isEmpty(expertiseList)) {
            return StrUtil.EMPTY;
        }
        return expertiseList.stream()
                .map(Expertise::getExpertiseName)
                .collect(Collectors.joining(ChineseCharacter.C_CHINESE_COMMA));
    }

    @Override
    public List<String> fetchCounselorDetailExpertise(String counselorId) {
        List<Expertise> expertiseList = expertiseMapper.selectByCounselor(counselorId);
        if (CollectionUtil.isEmpty(expertiseList)) {
            return Collections.emptyList();
        }
        List<String> newExpertiseList = new ArrayList<>();
        for (Expertise expertise : expertiseList) {
            newExpertiseList.add(expertise.getExpertiseName());
        }
        return newExpertiseList;
    }
}
